<?php
// $Id: search-result.tpl.php,v 1.1.2.1 2008/08/28 08:21:44 dries Exp $

/**
 * @file search-result.tpl.php
 * Default theme implementation for displaying a single search result.
 *
 * This template renders a single search result and is collected into
 * search-results.tpl.php. This and the parent template are
 * dependent to one another sharing the markup for definition lists.
 *
 * Available variables:
 * - $url: URL of the result.
 * - $title: Title of the result.
 * - $snippet: A small preview of the result. Does not apply to user searches.
 * - $info: String of all the meta information ready for print. Does not apply
 *   to user searches.
 * - $info_split: Contains same data as $info, split into a keyed array.
 * - $type: The type of search, e.g., "node" or "user".
 *
 * Default keys within $info_split:
 * - $info_split['type']: Node type.
 * - $info_split['user']: Author of the node linked to users profile. Depends
 *   on permission.
 * - $info_split['date']: Last update of the node. Short formatted.
 * - $info_split['comment']: Number of comments output as "% comments", %
 *   being the count. Depends on comment.module.
 * - $info_split['upload']: Number of attachments output as "% attachments", %
 *   being the count. Depends on upload.module.
 *
 * Since $info_split is keyed, a direct print of the item is possible.
 * This array does not apply to user searches so it is recommended to check
 * for their existance before printing. The default keys of 'type', 'user' and
 * 'date' always exist for node searches. Modules may provide other data.
 *
 *   <?php if (isset($info_split['comment'])) : ?>
 *     <span class="info-comment">
 *       <?php print $info_split['comment']; ?>
 *     </span>
 *   <?php endif; ?>
 *
 * To check for all available data within $info_split, use the code below.
 *
 *   <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
 *
 * @see template_preprocess_search_result()
 * add the video image stuff into this template...
 */
?>
<dt class="title">
  <a href="<?php print $url; ?>"><?php print $info_split['user']; ?><?php print $title; ?></a>
</dt>
<dd>
  <?php 
  if ($snippet) : 
    $pattern='~COURSE_CODE_START ((<strong>)?(.*)(\/|<.*)) COURSE_CODE_END~';
    if(preg_match($pattern, $snippet, $matches)){
      $replace_main='\3';
      $replace_code_only= preg_replace($pattern, $replace_main, $matches[0]);
      $c_code= "<a href=\"?q=videofinder/list/" . $replace_code_only . "/course_code\" title=\"View course video\">" . $replace_code_only . "</a>";
      $replace='\2' . $c_code . '\4';
      $pattern_to_remove='/COURSE_CODE_START ((<strong>)?(.*)(\/|<.*)) COURSE_CODE_END/';
      $snippet= preg_replace($pattern_to_remove, $replace, $snippet );
    }else{
      $pattern='~COURSE_CODE_START ([A-z,0-9]*)(/?.*) COURSE_CODE_END~';
      $replace_main='\1';
      $replace_trailing='\2';
      $c_code= "<a href=\"?q=videofinder/list/$replace_main/course_code\" title=\"View video for this module\">" . $replace_main . "</a>$replace_trailing";
      $snippet= preg_replace($pattern, $c_code, $snippet ); 
    }?>
    <p class="search-snippet"><?php print $snippet; 
   ?>
   </p>
  <?php endif; ?>
  <?php /* we don;t want to show mod date so we'll turn this off
if ($info) : ?>
  <p class="search-info"><?php print $info_split['date']; ?></p>
  <?php endif;  */ ?>
</dd>
